package utils

import (
	"fmt"
	"math/rand"
	"time"
)

// 生成随机数
func RandInt(min, max int) int {
	if min >= max || min == 0 || max == 0 {
		return max
	}
	return rand.Intn(max-min+1) + min
}

func TimeStr(mo int) string {
	//时间
	year, month, day := time.Now().Date()
	mon := uint(month) + uint(mo)

	var time1 string
	if day > 28 && mon-12 == 2 {
		mon += 1
		day = 0
	}
	fmt.Println(">>>", day)
	fmt.Println(">>>", mon)
	if mon > 12 {

		yea := uint(year) + 1
		mons := fmt.Sprintf("%v", mon-12)
		days := fmt.Sprintf("%v", day)
		if len(fmt.Sprintf("%v", mon-12)) == 1 {
			mons = "0" + fmt.Sprintf("%v", mon-12)
		}
		if day == 0 {
			days = "0" + fmt.Sprintf("%v", day+1)
		}

		time1 = fmt.Sprintf("%v", yea) + "-" + mons + "-" + days

	} else {
		mons := fmt.Sprint(mon)
		fmt.Println("=============", mons)
		if len(fmt.Sprintf("%v", mon)) == 1 {
			mons = "0" + fmt.Sprintf("%v", mon)
		}
		if mon != 1 || mon != 3 || mon != 5 || mon != 7 || mon != 8 || mon != 10 {
			if day == 31 {
				if mon == 12 {
					time1 = fmt.Sprintf("%v", year+1) + "-" + "01" + "-" + "01"
				} else {
					time1 = fmt.Sprintf("%v", year) + "-" + fmt.Sprint(mon+1) + "-" + "01"
				}
			} else {
				time1 = fmt.Sprintf("%v", year) + "-" + fmt.Sprint(mon) + "-" + fmt.Sprintf("%v", day)
			}
		} else {
			time1 = fmt.Sprintf("%v", year) + "-" + mons + "-" + fmt.Sprintf("%v", day)
		}
	}
	//time生成
	hour := time.Now().Hour()     //小时
	minute := time.Now().Minute() //分钟
	second := time.Now().Second() //秒

	time2 := time1 + " " + fmt.Sprint(hour) + ":" + fmt.Sprint(minute) + ":" + fmt.Sprint(second)
	return time2
}
